

#ifndef _SERIALHMI_STRUCT_H_
#define _SERIALHMI_STRUCT_H_

#include "stdint.h"

#define HMI_FRAME_HEAD     0xF0F0
#define HMI_FRAME_HEAD_H   0xF0
#define HMI_FRAME_HEAD_L   0xF0

#define HMI_COMM_FRAME_LENGTH  0x0A


#define ID_CMD_HMI_TO_MCU  0x18EF
#define ID_OTA_HMI_TO_MCU  0x18F0

#define ID_ACK_MCU_DATA    0xFE18
#define ID_ACK_MCU_PARAM   0xFE19

#define ID_ACK_MCU_PLOT    0xFE1A


// HMI first byte function define

typedef enum
{
	HMI_DATA_LIST = 0x5A,
	HMI_CTRL_CMD  = 0x5B,
	HMI_FLT_CLEAR = 0x54,
	HMI_PARAM_SAVE= 0x55,
	HMI_DATA_PLOT = 0x5F,
	HMI_READ_ALL  = 0x51,
	HMI_READ_ONE  = 0x52,
	HMI_WRITE_ONE = 0x53,
	
	
	HMI_USER_CMD  = 0xAA,
	HMI_USER_ACK  = 0xFA,
	
	
	HMI_OTA_CMD   = 0xFF

}ENUM_HMI_CMD_TYPE;


// HMI key cmd function define

typedef enum
{
	HMI_KEY_FUN   = 0x01,
	HMI_KEY_VALUE = 0x02,
	HMI_KEY_REF1  = 0x03,
	HMI_KEY_REF2  = 0x04

}ENUM_HMI_KEY_TYPE;


// HMI fault clear function define 

typedef enum
{
	HMI_CLEAR_FLT = 0x01,
	HMI_CLEAR_HIS = 0x02,

}ENUM_HMI_CLEAR_TYPE;


// HMI OTA sub function num define

typedef enum
{
	HMI_OTA_SHAKE    = 0x01,
	HMI_OTA_BACKUP   = 0x02,
	HMI_OTA_ERASE    = 0x03,
	HMI_OTA_ROLLBACK = 0x04,
	HMI_OTA_RESET    = 0xFF

}ENUM_HMI_OTA_NUM;





// Serial HMI transmit data framework

typedef struct
{
	uint16_t  head;
	uint16_t  count;
	
	uint16_t  length;
	uint16_t  ID;
	
	uint8_t* databuf;
	
	uint8_t  CRC_L;
	uint8_t  CRC_H;

}STR_HMI_FRAME;



// --------------- serial data receive from HMI ---------------------

// HMI cmd payload define (0x5A 0x54 0x51 0x52)

typedef union  // HMI
{
	struct
	{
		uint16_t InsNum   :8;
		uint16_t xx       :8;
		uint16_t IndexEx  :8;
		uint16_t IndexIn  :8;
		uint16_t Data1    :8;
		uint16_t Data2    :8;
		uint16_t Reserve1 :8;
		uint16_t Reserve2 :8;
	};
	
	uint8_t data[8];

}STR_HMI_FUNNUM;


// HMI key ctrl payload define (0x5B)

typedef union   // HMI
{
	struct 
	{
		uint16_t InsNum    :8;
		uint16_t FunNum    :8;		
		uint16_t enable    :8;
		uint16_t brake     :8;
		uint16_t mode      :8;
		uint16_t fun       :8;
		uint16_t Reserve1  :8;
		uint16_t Reserve2  :8;	
	};

	uint8_t data[8];

}STR_HMI_KEYCMD;


typedef union  // HMI
{
	struct
	{
		uint16_t InsNum    :8;
		uint16_t FunNum    :8;	

		int16_t frontback  :16;
		int16_t leftright  :16;

		uint16_t Reserve1  :8;
		uint16_t Reserve2  :8;	
	};

	uint8_t data[8];


}STR_HMI_KEYVALUE;


typedef union  // HMI
{
	struct
	{
		uint16_t InsNum    :8;
		uint16_t FunNum    :8;	

		uint16_t cmd1      :16;
		uint16_t cmd2      :16;		
		uint16_t cmd3      :16;
	};
	
	uint8_t data[8];

}STR_HMI_KEYREF;


// HMI plot cmd payload define (0x5F)

typedef union
{
	struct
	{
		uint8_t InsNum    :8;
		uint8_t FunNum    :8;
		uint16_t Index1   :16;
		uint16_t Index2   :16;
		uint16_t Index3   :16;
	};
	
	uint8_t data[8];

}STR_HMI_PLOTCMD;


// HMI param write one payload define (0x53)

typedef union
{
	struct 
	{
		uint16_t InsNum   :8;
		uint16_t xx       :8;
		uint16_t yy       :8;
		uint16_t addr     :8;
		uint16_t value    :16;
		uint16_t Index    :16;
	};
	
	uint8_t data[8];

}STR_HMI_WRITEONE;



// --------------- serial data transmit from MCU ---------------------

// HMI data monitor list payload define (0x5A 0x51)

typedef union  // MCU
{
	struct
	{
		uint16_t Data1   :16;
		uint16_t Data2   :16;
		uint16_t Data3   :16;
		uint16_t Index   :8;
		uint16_t Reserve :8;
	};
	
	uint8_t data[8];

}STR_HMI_DATALIST;


// HMI ACK data payload define (0x53 0x54)

typedef union  // MCU 
{
	struct
	{
		uint16_t InsNum       :8;
		uint16_t xx           :8;
		uint16_t ctrlRes      :8;
		uint16_t paramAddr    :8;
		uint16_t writeRes     :8;
		uint16_t yy           :8;
		uint16_t paramIndex   :16;
	};
	
	uint8_t data[8];

}STR_HMI_CMDACK;
	

// HMI plot data payload define (0x5F)

typedef union 
{
	struct
	{
		uint16_t Data1  :16;
		uint16_t Index1 :16;
		uint16_t Data2  :16;
		uint16_t Index2 :16;
	};
	
	uint8_t data[8];
	
}STR_HMI_PLOTDATA;








#endif




